﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fibre.Threading.Tests
{
    [TestClass]
    public class MethodSignatureTests
    {
        [TestMethod]
        public void action_method_signatures()
        {
            var worker = new AsyncWork();

            Assert.IsInstanceOfType(worker.AddWork(() => { }), typeof(IWorkContext));
        }

        [TestMethod]
        public void func_method_signatures()
        {
            var worker = new AsyncWork();

            Assert.IsInstanceOfType(worker.AddWork(() => "" ), typeof(IWorkContext<string>));
        }

        [TestMethod]
        public void async_pattern_with_no_arguments_method_signatures()
        {
            Action action = () => { };
            Func<string> func = () => "";
            var worker = new AsyncWork();

            Assert.IsInstanceOfType(worker.AddWork(action.BeginInvoke, action.EndInvoke), typeof(IWorkContext));
            Assert.IsInstanceOfType(worker.AddWork<string>(func.BeginInvoke, func.EndInvoke), typeof(IWorkContext<string>));
        }

        [TestMethod]
        public void async_pattern_with_one_argument_method_signatures()
        {
            Action<int> action = i => { };
            Func<int, string> func = i => "";
            var worker = new AsyncWork();

            Assert.IsInstanceOfType(worker.AddWork(action.BeginInvoke, 1, action.EndInvoke), typeof(IWorkContext));
            Assert.IsInstanceOfType(worker.AddWork<int, string>(func.BeginInvoke, 1, func.EndInvoke), typeof(IWorkContext<string>));
        }

        [TestMethod]
        public void async_pattern_with_two_arguments_method_signatures()
        {
            Action<int, string> action = (i, s) => { };
            Func<int, string, string> func = (i, s) => "";
            var worker = new AsyncWork();

            Assert.IsInstanceOfType(worker.AddWork(action.BeginInvoke, 1, "test", action.EndInvoke), typeof(IWorkContext));
            Assert.IsInstanceOfType(worker.AddWork<int, string, string>(func.BeginInvoke, 1, "test", func.EndInvoke), typeof(IWorkContext<string>));
        }
    }
}
